package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManageClickLog;
import com.hunttown.mes.rpc.domain.AnalysisManageClickLogDTO;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:05:11
 */
public class AnalysisManageClickLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageClickLogConverts.class);

    public static List<AnalysisManageClickLogDTO> convert(List<AnalysisManageClickLog> analysisManageClickLogList) {
        if (CollectionUtils.isEmpty(analysisManageClickLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageClickLogDTO> analysisManageClickLogListResult = Lists.newArrayList();
        for (AnalysisManageClickLog analysisManageClickLog : analysisManageClickLogList) {
            analysisManageClickLogListResult.add(convert(analysisManageClickLog));
        }
        return analysisManageClickLogListResult;
    }

    public static AnalysisManageClickLogDTO convert(AnalysisManageClickLog analysisManageClickLog) {
        try {
            return BeanUtils.copy(analysisManageClickLog, AnalysisManageClickLogDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageClickLog到AnalysisManageClickLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageClickLog到AnalysisManageClickLogDTO转换失败", e);
        }
    }

    public static AnalysisManageClickLog convert(AnalysisManageClickLogDTO analysisManageClickLogDTO) {
        try {
            return BeanUtils.copy(analysisManageClickLogDTO, AnalysisManageClickLog.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageClickLogDTO到AnalysisManageClickLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageClickLogDTO到AnalysisManageClickLog转换失败", e);
        }
    }
}